package com.lei2j.state;

/**
 * Created by lei2j on 2019/2/4.
 */
public class WinnerState implements State {

    private GumballaMachine gumballaMachine;

    public WinnerState(GumballaMachine gumballaMachine) {
        this.gumballaMachine = gumballaMachine;
    }

    @Override
    public void dispense() {
        gumballaMachine.releaseBall();
        if (gumballaMachine.getCount()>0){
            gumballaMachine.releaseBall();
            if (gumballaMachine.getCount()>0){
                gumballaMachine.setState(gumballaMachine.getNoQuarterState());
            }else {
                gumballaMachine.setState(gumballaMachine.getSoldoutState());
            }
        }
    }
}
